﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Security.Server;
namespace LightSwitchApplication
{
    public partial class ApplicationDataService
    {
        partial void Accounts_All_PreprocessQuery(ref IQueryable<Account> query)
        {
            // sort accounts by LastName, FirstName by default
            query = from a in query
                    orderby a.Name, a.FirstName
                    select a;
                      
        }

        partial void Accounts_Validate(Account entity, EntitySetValidationResultsBuilder results)
        {
            if (string.IsNullOrEmpty(entity.Key))
            {
                results.AddEntityError("Please insert a key!");
            }
        }

        partial void AvailableAccountLocations_PreprocessQuery(int? AccountId, ref IQueryable<Location> query)
        {
            if (AccountId != null)
            {
                int id = Convert.ToInt32(AccountId);

                query = from l in query
                        where l.Account.Id == id
                        select l;
            }
        }
    }
}
